package org.codeart.juc.queue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * 同步队列
 */
public class SynchronousQueueDemo {

    public static final Integer signal = 1;

    public static void main(String[] args) throws InterruptedException {
        // 不存储数据 存储生产者
        SynchronousQueue<Integer> queue = new SynchronousQueue<>();

        Thread t1 = new Thread(() -> {
            boolean b = false;
            try {
                b = queue.offer(signal, 1, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(b);
        });
        t1.start();
        
        Thread t2 = new Thread(() -> {
            try {
                System.out.println(queue.poll(1, TimeUnit.SECONDS));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t2.start();
    }

}
